package com.asa.common.net

import com.asa.base.BaseApplication
import com.asa.common.common.AppConstants
import com.asa.common.common.AppUtils
import com.asa.common.common.AppUtils.getPackageName
import okhttp3.Interceptor
import okhttp3.Response

class HttpCacheInterceptor:Interceptor{

    override fun intercept(chain: Interceptor.Chain): Response {
        var request  = chain.request()
        val builder = request.newBuilder()
        request = builder.addHeader(AppConstants.ACCOUNT_ID, BaseApplication.userId.toString())
            .addHeader(AppConstants.APP_PLATFORM, AppConstants.APP_PLATFORM_BBK)
//            .addHeader(AppConstants.DEVICE_MODEL, DeviceUtils.getModel())
            .addHeader(AppConstants.APK_PACKAGE_NAME, AppUtils.getPackageName(BaseApplication.appContext))
            .addHeader(AppConstants.APK_VERSION_CODE, AppUtils.getVersionCode(BaseApplication.appContext).toString())
            .addHeader(AppConstants.APK_VERSION_NAME, AppUtils.getVersionName(BaseApplication.appContext).toString())
            .addHeader(AppConstants.TOKEN, BaseApplication.token?:"")
            .addHeader(AppConstants.CONTENT_TYPE, AppConstants.CONTENT_TYPE_VALUE)
            .addHeader(AppConstants.USER_ID, BaseApplication.userId.toString())
//            .addHeader(AppConstants.OPEN_ID, UserInfoManager.openId)
            .addHeader(AppConstants.USER_FLAG, "rd_test")
            .addHeader(AppConstants.APP_KEY, "RD")
            .build()

        val response = chain.proceed(request)
        return response
    }

}